<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>登陆</span>
      </div>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="登陆名" prop="account">
          <el-input v-model="ruleForm.account"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pwd">
          <el-input type="password" v-model="ruleForm.pwd"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">登陆</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        account: "",
        pwd: "",
      },
      rules: {
        account: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        pwd: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$ajax.post(`/admin/login?account=${this.ruleForm.account}&pwd=${this.ruleForm.pwd}`,{}).then(res => {
            if (res.code == "1") {
                this.$message.error(res.msg);
            }else{
                localStorage.setItem('menuList',JSON.stringify(res.data.menuList)) //菜单列表
                this.$cookies.set('userInfo',res.data.login) //用户信息
                console.log(res.data)
                localStorage.setItem('bsyy',JSON.stringify(res.data.bsyy)) //报损原因
                localStorage.setItem('sxmd',JSON.stringify(res.data.sxmd)) //输血目的
                localStorage.setItem('xydm',JSON.stringify(res.data.xydm)) //血液代码
                localStorage.setItem('xylx',JSON.stringify(res.data.xylx)) //血液类型
                localStorage.setItem('bqdm',JSON.stringify(res.data.bqdm)) //病区代码
                this.$message({
                    message: '登陆成功',
                    type: 'success'
                });
                setTimeout(() => {
                    this.$router.push({
                        name:'home'
                    })
                }, 1000);
            }
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.box-card {
  width: 450px !important;
  margin: 100px auto 0;
}
</style>